package cn.alpha.intell.rbtlib.view.widget.common;

import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.alpha.intell.rbtlib.R;
import cn.alpha.intell.rbtlib.broadcast.OSApp;
import cn.alpha.intell.rbtlib.utils.StartAppUtil;

/**
 * Created by zhangxiliang on 2017/1/11.
 */
public class BadNetView  extends RelativeLayout{


    public View mView;
    public TextView mSettingBtn;
    private Context mContext;
    private ViewGroup mViewGroup;
    public BadNetView(Context context, ViewGroup viewGroup) {
        super(context);
        this.mContext=context;
        this.mViewGroup=viewGroup;
        init(context);
    }

    public BadNetView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void init(Context context){
        LayoutInflater layoutInflater=LayoutInflater.from(context);
        mView=layoutInflater.inflate(R.layout.item_bad_net,null);

        RelativeLayout relativeLayout=new RelativeLayout(mContext);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL,RelativeLayout.TRUE);
        lp.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
        lp.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
        relativeLayout.addView(mView,lp);

        mSettingBtn=(TextView)mView.findViewById(R.id.btn_go_setting);
        mSettingBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                StartAppUtil.startAppByPkgName(OSApp.SETTING.getValue(),new Bundle());
            }
        });
        mView.setVisibility(GONE);
        mViewGroup.addView(relativeLayout);
    }


    public void show(){
        if(mView!=null){
            mView.setVisibility(VISIBLE);
        }
    }

    public void hiden(){
        if(mView!=null){
            mView.setVisibility(GONE);
        }
    }

}
